package com.han.agent.advisor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClientRequest;
import org.springframework.ai.chat.client.ChatClientResponse;
import org.springframework.ai.chat.client.advisor.api.CallAdvisor;
import org.springframework.ai.chat.client.advisor.api.CallAdvisorChain;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.prompt.Prompt;

@Slf4j
public class LoggerAdvisor implements CallAdvisor {

    @Override
    public ChatClientResponse adviseCall(ChatClientRequest request, CallAdvisorChain chain) {
        log.info("BEFORE: {}", request);

        ChatClientRequest.Builder newRequestBuild = request.mutate().prompt(Prompt.builder().messages(new SystemMessage("参照李清照的风格")).build());
        ChatClientResponse response = chain.nextCall(newRequestBuild.build());

        log.info("AFTER: {}", response);

        return response;
    }

    @Override
    public String getName() {
        return this.getClass().getSimpleName();
    }

    @Override
    public int getOrder() {
        // 数字越小，越先执行
        return 0;
    }
}
